{template header}
<!--main-->
<style>
    .menu a{
        color:black;
        font-weight:normal;
        font-size:10px
    }
    .menu .active{
        font-weight:bold
    }


</style>
<div class="container">


    <div class="row top10">
        <dl>
            <dd>


           <h3 style="padding:10px;display: flex ">

                义卖交易明细表
               {if !isMobile()&&$GLOBALS['TS_USER']['isadmin']=='1' }
               <a style="margin-left: 50px;color: black;float: right;"  data-toggle="modal" data-target="#do_export_form">导出</a>
               {/if}
          </h3>


    <ul><li >
        <span style="width: 20%">订单号</span><span style="width: 17%">物品</span><span style="width:10%">金额</span><span style="width:10%">捐赠人</span><span style="width:10%">买家</span> <span style="width:14%">支付日期</span>
        </li>
    </ul>
         <ul>
        {loop $arrTrade $key $item}
            <li>
           <span style="width: 20%;{if $item['status']==-1}text-decoration:line-through{/if}">{$item['trade_no']}</span>
           <span style="width: 17%;{if $item['status']==-1}text-decoration:line-through{/if}"><a href="{tsUrl('gift','show',array('id'=>$item['gift']['giftid']))}">{$item['gift']['title']}</a>
           </span>
           <span style="width: 10%;{if $item['status']==-1}text-decoration:line-through{/if}">{$item[price]}</span>
           <span style="width: 10%;{if $item['status']==-1}text-decoration:line-through{/if}"><a href="{tsUrl('user','duty',array('userid'=>$item['seller']['userid']))}">{$item['seller']['username']}</a></span>
           <span style="width: 10%;{if $item['status']==-1}text-decoration:line-through{/if}"><a href="{tsUrl('user','duty',array('userid'=>$item['buyer']['userid']))}">{$item['buyer']['username']}</a></span>
            <span style="width: 14%;{if $item['status']==-1}text-decoration:line-through{/if}">
                    {php echo date('Y-m-d H:i:s',$item['addtime'])}
            </span>
                <span style="width: 10%">{if $item['status']==1}<a href="javascript:void('0');" onclick='refund({$item[payid]})'>退款</a>{/if}<span>
             </li>
        {/loop}
        </ul>
                </dd>
            </dl>
        <div class="page">{$pageUrl}</div>
    </div>

</div>


<div id="do_export_form" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" >
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h5 class="modal-title">筛选范围</h5>
            </div>
            <div class="modal-body" >
                <form  id="open-form" class="form-horizontal" method="post" action="{SITE_URL}index.php?app=gift&ac=do&ts=export">


                    <div class="form-group">
                        <label class="col-sm-2 control-label">起始日期</label>
                        <div class="col-sm-3"><select  data-name="year" name="beginyear" class="form-control"></select></div>
                        <div class="col-sm-3"><select  data-name="month" name="beginmonth" class="form-control"></select></div>
                        <div class="col-sm-3"><select  data-name="day"  name="beginday" class="form-control"></select></div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">截止日期</label>
                        <div class="col-sm-3"><select  data-name="year" name="endyear" class="form-control"></select></div>
                        <div class="col-sm-3"><select  data-name="month" name="endmonth" class="form-control"></select></div>
                        <div class="col-sm-3"><select  data-name="day"  name="endday" class="form-control"></select></div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <button type="submit" class="btn btn-success">点击提交</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script>
    $(document).ready(function(e) {
        var date = new Date();
        var vYear = date.getFullYear();
        var vMon = date.getMonth() + 1;
        var vDay = date.getDate();
        var year;
        var month;
        var day;
        var str_year;
        var str_month;
        var t_month;
        var str_day;

        {if $myDuty!=''}
            vYear = {php echo date('Y',$myDuty['begintime'])};
            vMon  = {php echo date('m',$myDuty['begintime'])};
            vDay  = {php echo date('d',$myDuty['begintime'])};
            {/if}

                var first_year = 2017;
//起始
                var last_year = date.getFullYear();
//终止年
                var t_year
                var i;
                var r;
                var y_v;
                var m_v;
                var d_v;
//写出年的选项
                $("[data-name=year]").append('<option value=""></option>');
                for (i = last_year; i >= first_year; i--) {

                    if (i != vYear) {
                        $("[data-name=year]").append('<option value="' + i + '">' + i + '</option>');
                    } else {
                        $("[data-name=year]").append('<option value="' + i + '" selected>' + i + '</option>');
                    }
                }
//写出月的选项
                $("[data-name=month]").append('<option value=""></option>');
                for (i = 1; i <= 12; i++) {
                    r = i ;
                    if (i != vMon) {
                        $("[data-name=month]").append('<option value="' + i + '">' + r + '</option>');
                    } else {
                        $("[data-name=month]").append('<option value="' + i + '" selected>' + r + '</option>');
                    }
                }

//初始化日的值
                day();
//在年月的值发生变化时计算日期的天数
                $("[data-name=year]").change(function(){   day();   });
                $("[data-name=month]").change(function(){ day();
                });
//根据日期的天数，输出日选项

                function day(){
                    var y_v=$("[data-name=year]").val();
                    var m_v=$("[data-name=month]").val()-1;
                    var d_v;
                    var i;
                    if((y_v%100!=0&&y_v%4==0)||y_v%400==0) {
                        d_v=new Array(31,29,31,30,31,30,31,31,30,31,30,31);
                    }    else   {
                        d_v=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
                    }
                    $("[data-name=day]").html("");
                    $("[data-name=day]").append('<option value=""></option>');
                    for(i=1;i<=d_v[m_v];i++)   {
                        //if(i!=vDay)  {
                        $("[data-name=day]").append('<option value="'+i+'">'+i+'</option>');
                        //	}  else {
                        //	$("[data-name=day]").append('<option value="'+i+'" selected>'+i+'</option>');
                        //	}
                    }
                }
            });

//退款
function refund(payid){
    if (confirm('确定要退款吗？')) {
        $.ajax({
            type: "POST",
            url: siteUrl+"index.php?app=gift&ac=do&ts=refund",
            data: "payid="+payid,
            beforeSend:function(){
            },
            success:function(result){
                if(result == '1'){
                    window.location.reload();
                }
            }
        });

    }
}

</script>




{template footer}